<?php

namespace App\Api;

use App\Http\Controllers\Controller;
use App\Http\Requests\ArticleRequest;
use App\Models\Article;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ArticleController extends Controller
{

    public function __construct()
    {
        $this->middleware('auth:sanctum');
    }

    public function index()
    {
        $articles = Article::all();
        return $articles->toArray();
    }


    public function store(ArticleRequest $request, Article $article)
    {
        $article->fill($request->input())->save();
        return $this->message('模型创建成功');
    }

    public function show(Article $article)
    {
        return $article;
    }


    public function edit(Article $article)
    {
        //
    }


    public function update(ArticleRequest $request, Article $article)
    {

        $article->update($request->input());
        return $this->message('更新成功');
    }


    public function destroy(Article $article)
    {
        $article->delete();
        return $this->message('删除成功');
    }

    public function publish()
    {
        return Article::all()->take(4);
    }
}
